
package jh.com.jhappbf.weight.query;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.ab.activity.AbActivity;
import com.ab.view.titlebar.AbTitleBar;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import androidx.core.content.ContextCompat;
import jh.com.jhappbf.R;
import jh.com.jhappbf.utils.ImageLoadHelper;

/**
 * @author Administrator
 */
public class QueryWeightImage extends AbActivity {
    private ArrayList<String> mList = new ArrayList<>();// 图标字段
    private Map<String, ImageView> mImageViews = new HashMap<>();
    private Map<String, ProgressBar> mProgressBars = new HashMap<>();
    private Context mAppContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setAbContentView(R.layout.query_weight_image_activity);
        AbTitleBar mAbTitleBar = this.getTitleBar();
        mAbTitleBar.setTitleText(R.string.query_weight_img_title);
        mAbTitleBar.setLogo(R.drawable.button_selector_back);
        mAbTitleBar.setTitleBarBackgroundColor(ContextCompat.getColor(this, R.color.orange));
        mAbTitleBar.setTitleTextMargin(10, 0, 0, 0);
        mAbTitleBar.setLogoLine(R.mipmap.line);
        initView();
    }

    /**
     * 初始化
     */
    private void initView() {
        Intent i = getIntent();
        String id = i.getStringExtra("flag");
        mAppContext = getApplicationContext();
        mList.add("m0");
        mList.add("m1");
        mList.add("m2");
        mList.add("m3");
        mList.add("p0");
        mList.add("p1");
        mList.add("p2");
        mList.add("p3");
        int index = 0;

        mImageViews.put(mList.get(index), findViewById(R.id.query_weight_gross_first_img));
        mProgressBars.put(mList.get(index), findViewById(R.id.query_weight_gross_first_progress));
        index++;

        mImageViews.put(mList.get(index), findViewById(R.id.query_weight_gross_second_img));
        mProgressBars.put(mList.get(index), findViewById(R.id.query_weight_gross_second_progress));
        index++;

        mImageViews.put(mList.get(index), findViewById(R.id.query_weight_gross_third_img));
        mProgressBars.put(mList.get(index), findViewById(R.id.query_weight_gross_third_progress));
        index++;

        mImageViews.put(mList.get(index), findViewById(R.id.query_weight_gross_fourth_img));
        mProgressBars.put(mList.get(index), findViewById(R.id.query_weight_gross_fourth_progress));
        index++;

        mImageViews.put(mList.get(index), findViewById(R.id.query_weight_tare_first_img));
        mProgressBars.put(mList.get(index), findViewById(R.id.query_weight_tare_first_progress));
        index++;

        mImageViews.put(mList.get(index), findViewById(R.id.query_weight_tare_second_img));
        mProgressBars.put(mList.get(index), findViewById(R.id.query_weight_tare_second_progress));
        index++;

        mImageViews.put(mList.get(index), findViewById(R.id.query_weight_tare_third_img));
        mProgressBars.put(mList.get(index), findViewById(R.id.query_weight_tare_third_progress));
        index++;

        mImageViews.put(mList.get(index), findViewById(R.id.query_weight_tare_fourth_img));
        mProgressBars.put(mList.get(index), findViewById(R.id.query_weight_tare_fourth_progress));
//        index++;
        loadImage(id);
    }

    //加载图片
    private void loadImage(String id) {
        if (TextUtils.isEmpty(id)) {
            return;
        }
        for (String item : mList) {
            new ImageLoadHelper(mAppContext, mImageViews.get(item), mProgressBars.get(item), new WeakReference<>(this)).loadImage(item, id);
        }
    }

    @Override
    protected void onStop() {
        super.onStop();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        for (String item : mImageViews.keySet()) {
            ImageLoadHelper.bitmapClear(mImageViews.get(item));
        }
    }
}
